<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('文件列表')" />
</head>
<body class="gray-bg">
    <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="menu-form">
					<div class="select-list">
						<ul>
							<li>
								文件名称：<input type="text" name="fName"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
                
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-info" id="expandAllBtn">
                    <i class="fa fa-exchange"></i> 展开/折叠
                </a>
	        </div>
       		 <div class="col-sm-12 select-table table-striped">
	            <table id="bootstrap-tree-table"></table>
	        </div>
	    </div>
	</div>
	
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var addFlag = [[${@permission.hasPermi('busi:repository_file:add')}]];
		var editFlag = [[${@permission.hasPermi('busi:repository_file:edit')}]];
		var removeFlag = [[${@permission.hasPermi('busi:repository_file:remove')}]];
		var datas = [[${@dict.getType('sys_show_hide')}]];
		var fileType = [[${@dict.getType('file_type')}]];
		var prefix = ctx + "busi/file/msg";
		var delFlag = [[${@dict.getType('del_flag')}]];
		var repositoryId = [[${repo.id}]];

		$(function() {
		    var options = {
		        code: "id",
		        parentCode: "parentId",
		        uniqueId: "id",
		        expandAll: true,
		        expandFirst: false,
				url: prefix + "/list/"+repositoryId,
		        createUrl: prefix + "/add/{repositoryId}/{parentId}",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove/{id}",
		        modalName: "kettle仓库",
		        columns: [{
					field: 'selectItem',
					radio: true
				},
					{
						field: 'fileName',
						title: '文件名称',
						width: '200',
						align: 'left'
					},
					{
						field: 'repositoryName',
						title: '仓库名称',
						width: '200',
						align: 'left',
					},
					{
						field: 'fileType',
						title: '文件类型',
						formatter: function (value, row, index) {
							return $.table.selectDictLabel(fileType, value);
						}
					},
					{
						field: 'delFlag',
						title: '是否删除',
						formatter: function (value, row, index) {
							return $.table.selectDictLabel(delFlag, value);
						}
					},
					{
						title: '删除时间',
						field: 'delTime'
					},
					{
						title: '启用状态',
						align: 'center',
						formatter: function (value, row, index) {
							return statusTools(row);
						}
					},
					{
						field: 'createdTime',
						title: '创建时间',
						sortable: true
					},
					{
						title: '操作',
						align: 'center',
						formatter: function (value, row, index) {
							var actions = [];
							if (row.fileType === '0') {
									actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="addFileOrDirectory(\'' + row.id + '\')"><i class="fa fa-edit"></i>导入</a> ');
								actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="addDirectory(\'' + row.id + '\')"><i class="fa fa-edit"></i>新增文件夹</a> ');
							} else {
								actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="switchVersion(\'' + row.id + '\')"><i class="fa fa-plus"></i>切换版本</a> ');
								actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="addFileVersion(\'' + row.id + '\')"><i class="fa fa-plus"></i>新增版本</a> ');
							}
							if (row.parentId !== 0) {

								actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-trash"></i>删除</a>');
							}
							return actions.join('');
						}
					}]
			};
		    $.treeTable.init(options);
		});

		function addFileOrDirectory(id) {
			var url = prefix + "/addFileOrDirectory/"+id;
			$.operate.addFileOrDirectory(url);
		}

		function addDirectory(id) {
			var url = prefix + "/addDirectory/"+id;
			$.modal.open("新增文件夹",url);
		}

		function addFileVersion(id) {
			var url = prefix + "/addVersion/"+id;
			$.modal.open("新增版本",url);
		}

		function switchVersion(id) {
            var url = prefix + "/switchVersion/"+repositoryId+"/"+id;
            $.modal.open("切换版本",url);
		}

		/* 状态显示 */
		function statusTools(row) {
			if (row.status == 1) {
				return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
			} else {
				return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
			}
		}

		/* 停用 */
		function disable(id) {
			$.modal.confirm("确认要停用吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 , fRepoId: repositoryId});
			})
		}

		/* 启用 */
		function enable(id) {
			$.modal.confirm("确认要启用吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 0 , fRepoId: repositoryId});
			})
		}
	</script>
</body>
</html>